package com.semanticweb.project.search.searchers;

import java.io.File;
import java.util.List;

import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;

import com.semanticweb.project.search.analyzer.SerbianAnalyzer;
import com.semanticweb.project.search.config.SearchConstants;

public class QuerySearcher {

	public static List<String> search(final File indexDir, final String q,
			final String field, final int docCount) {
		try {
			final QueryParser queryParser = new QueryParser(
					SearchConstants.LUCENE_VERSION, field,
					new SerbianAnalyzer());
			queryParser.setFuzzyMinSim(0.55f);
			queryParser.setPhraseSlop(0);
			final Query query = queryParser.parse(q);
			final ResultRetriever rr = new ResultRetriever(docCount);
			return rr.getResults(query, indexDir);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
}